<?php
/**
 * Created by PhpStorm.
 * User: jochen
 * Date: 2016/10/25
 * Time: 下午4:56
 */

namespace App;


trait MongoTypeFix
{
    public static function equalEmpty($field) {
        $query = <<<JSON
{"\$or":[{"$field":{"\$in":[0,"",null]}},{"$field":{"\$exists":false}}]}
JSON;
        $r = json_decode($query, 1);
        return $r;
    }

    public static function notEmpty($field) {
        $query = <<<JSON
{"$field":{"\$nin":[0,"",null]},"$field":{"\$exists":true}}
JSON;
        $r = json_decode($query, 1);
        return $r;
    }
}